package com.example.demo.task;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import com.example.demo.mapper.TorrentMapper;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;


@Component
public class PromotionTask {
    private final TorrentMapper torrentMapper;

    @Autowired
    public PromotionTask(TorrentMapper torrentMapper) {
        this.torrentMapper = torrentMapper;
    }

    @Scheduled(cron = "0 0/5 * * * ?") // 每5分钟执行一次
    public void checkPromotionStatus() {
        // 激活到期的促销
        torrentMapper.activateExpiredPromotions(LocalDateTime.now());

        // 关闭过期的促销
        torrentMapper.deactivateExpiredPromotions(LocalDateTime.now());
    }
}